package com.zjhcsoft.shop.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.zjhcsoft.common.dao.MybatisCommonDao;
import com.zjhcsoft.shop.dao.UserDao;
import com.zjhcsoft.shop.model.User;

@SuppressWarnings("unchecked")
@Repository
public class UserDaoImpl extends MybatisCommonDao<User, Long> implements UserDao{
	
	private static final Logger logger = Logger.getLogger(UserDaoImpl.class);
	
	public UserDaoImpl(){
		super.tableName="user";
		super.primaryKeyName="id";
	}
	/* (non-Javadoc)
	 * @see com.zjhcsoft.shop.dao.UserDao#inser(com.zjhcsoft.shop.model.User)
	 */
	public void  saveOrUpdate(User  entity){
		 try {
			super.saveOrUpdate(entity);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		}
	}
	
	public User loadByLoginName(String loginName){
		try {
			User user=new User();
			user.setLoginName(loginName);
			return super.loadEqual(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return null;
	}
	
	public List<User> getUserByLoginName(String loginName){
		try {
			return super.findByProperty(User.class, "loginName", loginName);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return null;
	}
	
}
